package database

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"rank-srv/global"
)

var Ctx = context.Background()

func Redis() {

	RedisConfig := global.Config.Redis

	Addr := fmt.Sprintf("%s:%d", RedisConfig.Host, RedisConfig.Port)

	global.Rdb = redis.NewClient(&redis.Options{
		Addr:     Addr,
		Password: RedisConfig.Password, // no password set
		DB:       RedisConfig.Database, // use default DB
	})

	err = global.Rdb.Ping(Ctx).Err()
	if err != nil {
		panic(err)
	}
}
